require 'tk'
require 'tk/validation'

root = TkRoot.new(title:"entrys demo")

var = TkVariable.new("")

TkLabel.new{
	text "File name : "
	grid padx:"1m",pady:"2m"
}

entry = TkEntry.new{
	width 20
	relief "sunken"
	bd 2
	textvariable var
	grid padx:"1m",pady:"2m"
}

entry.bind("KeyRelease"){
	#var.value = var.value.upcase
}

entry.bind("KeyPress"){
	var.value = var.value.upcase
}

months = TkVariable.new
months.value = %w[January February March April May June July August
			September October November December]
#months.set_element_value_type :String
puts months.list
month = TkVariable.new
TkLabel.new{
	text "Month : "
	grid padx:"1m",pady:"2m"
}
spinbox = TkSpinbox.new{
	width 20
	relief :sunken
	bd 2
	textvariable month
	state :readonly
	values months.list
	grid padx:"1m",pady:"2m"
}

TkLabel.new{
	text "Font size : "
	grid padx:"1m",pady:"2m"
}
size = TkVariable.new(100.0)
to_v = TkVariable.new(100.0)
#to_v.value = 100.0
from_v = TkVariable.new(5.0)
#from_v.value = 5.0
sb = TkSpinbox.new{
	width 20
	relief "sunken"
	bd 2
	textvariable size
	#from 5
	#to "100.0".to_f
	increment 5
	state "normal"
	grid padx:"1m",pady:"2m"
}
sb.configure(from:5,to:100)

TkLabel.new{
	text "password : "
	grid padx:"1m",pady:"2m"
}
TkEntry.new{
	show "#"
	grid sticky:"ew"
}
TkLabel.new{
	text "Must Input Number : "
	grid padx:"1m",pady:"2m"
}
v_entry = TkEntry.new{
	width 15
	validate "key"
	#vcmd proc {|s|s=~/[0-9]/},"%P"
	invalidcommand{
		Tk.bell
	}
	#validatecommand {
	#	validate_str
	#}
	
	#vcmd proc {|s|s=~/[0-9]/},"%S"
	vcmd(proc {|s| s=~/[0-9]/},"%S")
	grid padx:"1m",pady:"2m"
}
#v_entry.configure(vcmd:[->(x){puts x;return false},'%S'])

=begin
v_entry.validatecommand(cmd=->(x){
	puts x
	},args="%P")

def validate_str(str)
	puts str
end
=end

Tk.mainloop